package com.yurun.controller.admin;

import com.yurun.entity.Visitor;
import com.yurun.model.dto.VisitLogUuidTime;
import com.yurun.model.vo.Result;
import com.yurun.service.VisitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin")
public class VisitorAdminController {
    @Autowired
    VisitorService visitorService;
    /**
     * @Description: 添加访客
     * @Param: visitor
     * @return: com.yurun.model.vo.Result
     * @Author: JimmyYao
     * @Date: 2022/2/9
     */
    @PostMapping("/visitor")
    public Result addVisitor(@RequestBody Visitor visitor){
        visitorService.addVisitor(visitor);
        return Result.ok("添加访客成功");
    }
    /**
     * @Description: 删除访客
     * @Param: id
     * @return: com.yurun.model.vo.Result
     * @Author: JimmyYao
     * @Date: 2022/2/9
     */
    @DeleteMapping("/visitor/id")
    public Result deleteVisitorById(@RequestParam Long id){
        visitorService.deleteVisitorById(id);
        return Result.ok("删除访客成功");
    }
    /**
     * @Description: 更新今日访客数量与访客最后登录时间
     * @Param: dto
     * @return: com.yurun.model.vo.Result
     * @Author: JimmyYao
     * @Date: 2022/2/9
     */
    @PutMapping("/pvandlasttime/uuid")
    public Result updatePVAndLastTimeByUUID(@RequestBody VisitLogUuidTime dto){
        visitorService.updatePVAndLastTimeByUUID(dto);
        return Result.ok("更新今日访客数量和访客最后登录时间成功");
    }
    /**
     * @Description: 判断访客是否具有标识码
     * @Param: uuid
     * @return: com.yurun.model.vo.Result
     * @Author: JimmyYao
     * @Date: 2022/2/9
     */
    @GetMapping("/hasuuid")
    public Result hasUUID(@RequestParam String uuid){
        int object=visitorService.hasUUID(uuid);
        return Result.ok("获取用户是否具备标识码成功",object);
    }
    /**
     * @Description: 通过日期获取访客列表
     * @Param: startDate
     * @Param endDate
     * @return: com.yurun.model.vo.Result
     * @Author: JimmyYao
     * @Date: 2022/2/9
     */
    @GetMapping("/visitorlist/date")
    public Result getVisitorListByDate(@RequestParam String startDate,
                                       @RequestParam String endDate){
        List<Visitor> object=visitorService.getVisitorListByDate(startDate, endDate);
        return Result.ok("通过日期获取访客列表成功",object);
    }
    /**
     * @Description: 获取昨日新增访客IP资源
     * @Param:
     * @return: com.yurun.model.vo.Result
     * @Author: JimmyYao
     * @Date: 2022/2/9
     */
    @GetMapping("/newvisitoripsource")
    public Result getNewVisitorIpSourceByYesterDay(){
        List<String> object=visitorService.getNewVisitorIpSourceByYesterDay();
        return Result.ok("获取昨日新增访客的IP资源成功",object);
    }
}
